<template>
  <page-view :avatar="avatar" :title="false">
    <div slot="headerContent">
      <div class="title">{{ timeFix }}，{{ user.name }}</div>
    </div>
    

    <div>
      <a-row :gutter="24">
        <a-col :xl="16" :lg="24" :md="24" :sm="24" :xs="24">
          <a-card
            class="project-list"
            :loading="loading"
            style="margin-bottom: 24px;"
            :bordered="false"
            title="基础数据"
            :body-style="{ padding: 0 }">
            <div>
              <a-card-grid class="project-card-grid">
                <a-card :bordered="false" :body-style="{ padding: 0 }">
                  <a-card-meta>
                    <div slot="title" class="card-title">
                      <a-avatar size="small" :src="baseURL+'static/image/ico/xiaoqu.png'"/>
                      <a>小区</a>
                      <div class="sttm">{{baseData.mgCount}}个</div>
                    </div>
                  
                  </a-card-meta> 
                  <div class="project-item">
                    <router-link to="/data/community/operation/add">添加小区</router-link>
                  
                  </div>
                </a-card>
              </a-card-grid>
              <a-card-grid class="project-card-grid">
                <a-card :bordered="false" :body-style="{ padding: 0 }">
                  <a-card-meta>
                    <div slot="title" class="card-title">
                      <a-avatar size="small" :src="baseURL+'static/image/ico/louyu.png'"/>
                      <a>楼宇</a>
                      <div class="sttm">{{baseData.buildingCount}}个</div>
                    </div>
                  
                  </a-card-meta> 
                  <div class="project-item">
                    <router-link to="/data/building/operation/add">添加楼宇</router-link>
                  
                  </div>
                </a-card>
              </a-card-grid>
              <a-card-grid class="project-card-grid">
                <a-card :bordered="false" :body-style="{ padding: 0 }">
                  <a-card-meta>
                    <div slot="title" class="card-title">
                      <a-avatar size="small" :src="baseURL+'static/image/ico/fangwu.png'"/>
                      <a>房屋</a>
                      <div class="sttm">{{baseData.houseCount}}个</div>
                    </div>
                  
                  </a-card-meta> 
                  <div class="project-item">
                    <router-link to="/data/houses/operation/add">添加房屋</router-link>
                    <router-link to="/data/houses/import">导入房屋</router-link>
                  
                  </div>
                </a-card>
              </a-card-grid>
              <a-card-grid class="project-card-grid">
                <a-card :bordered="false" :body-style="{ padding: 0 }">
                  <a-card-meta>
                    <div slot="title" class="card-title">
                      <a-avatar size="small" :src="baseURL+'static/image/ico/zhuhu.png'"/>
                      <a>住户</a>
                      <div class="sttm">{{baseData.houseUserCount}}人</div>
                    </div>
                  
                  </a-card-meta> 
                  <div class="project-item">
                    <router-link to="/data/household/operation/add">添加住户</router-link>
                    <router-link to="/data/household/import">导入住户</router-link>
                  
                  </div>
                </a-card>
              </a-card-grid>
              <a-card-grid class="project-card-grid">
                <a-card :bordered="false" :body-style="{ padding: 0 }">
                  <a-card-meta>
                    <div slot="title" class="card-title">
                      <a-avatar size="small" :src="baseURL+'static/image/ico/chewei.png'"/>
                      <a>车位</a>
                      <div class="sttm">{{baseData.carAreaCount}}个</div>
                    </div>
                  
                  </a-card-meta> 
                  <div class="project-item">
                    <router-link to="/data/parking/operation/add">添加车位</router-link>
                    <router-link to="/data/parking/import">导入车位</router-link>
                  
                  </div>
                </a-card>
              </a-card-grid>
              <a-card-grid class="project-card-grid">
                <a-card :bordered="false" :body-style="{ padding: 0 }">
                  <a-card-meta>
                    <div slot="title" class="card-title">
                      <a-avatar size="small" :src="baseURL+'static/image/ico/cheliang.png'"/>
                      <a>车辆</a>
                      <div class="sttm">{{baseData.carCount}}个</div>
                    </div>
                  
                  </a-card-meta> 
                  <div class="project-item">
                    <router-link to="/data/vehicle/operation/add">添加车辆</router-link>
                    <router-link to="/data/vehicle/import">导入车辆</router-link>
                  
                  </div>
                </a-card>
              </a-card-grid>
            </div>
          </a-card>

          <a-card :loading="loadinggg" title="最新公告" :bordered="false">
            <a-list>
              <a-list-item :key="index" v-for="(item, index) in newGg">
                <a-list-item-meta>
                  <div slot="title">
                    <a @click="showOneNewGg(index)">{{ item.title }}</a>
                  </div>
                  <div slot="description">{{ item.create_at }}</div>
                </a-list-item-meta>
              </a-list-item>
            </a-list>
          </a-card>
        </a-col>
        <a-col
          style="padding: 0 12px"
          :xl="8"
          :lg="24"
          :md="24"
          :sm="24"
          :xs="24">
          <a-card title="快速开始 / 便捷导航" style="margin-bottom: 24px" :bordered="false" :body-style="{padding: 0}">
            <div class="item-group">
              <router-link to="/charge/cashier/index">收银台(常规)</router-link>
              <router-link to="/charge/cashier/others">其他收费</router-link>
              <router-link to="/charge/cashier/quick">临时停车费</router-link>
              <router-link to="/charge/copy_table">抄表录入</router-link>
              <router-link to="/charge/not_pay">未缴账单</router-link>
              <router-link to="/charge/be_pay">已缴账单</router-link>
              <router-link to="/charge/pre_deposit">业务收费台账</router-link>
              
            </div>
          </a-card>
          <a-card title="出入小区重点人群指数" style="margin-bottom: 24px" :loading="radarLoading" :bordered="false" :body-style="{ padding: 0 }">
            <div style="min-height: 400px;">
              <!-- :scale="scale" :axis1Opts="axis1Opts" :axis2Opts="axis2Opts"  -->
              <radar :data="radarData" />
            </div>
          </a-card>
          
        </a-col>
      </a-row>
      <a-modal
            :title="NewGgTitle"
            :visible="newGgShow"
            :width="900"
            :footer="null"
            @cancel='closeModels'
        >
        <div v-html="NewGgContent"></div>
      </a-modal>
    </div>
  </page-view>
</template>

<script>
import { timeFix } from '@/utils/util'
import { mapState ,mapGetters } from 'vuex'

import { PageView } from '@/layouts'
import HeadInfo from '@/components/tools/HeadInfo'
import { Radar } from '@/components'

import { getRoleList, getServiceList } from '@/api/manage'

const DataSet = require('@antv/data-set')

export default {
  name: 'Analysis',
  components: {
    PageView,
    HeadInfo,
    Radar
  },
  data () {
    return {
      baseURL:this.axios.defaults.baseURL,
      timeFix: timeFix(),
      avatar: '',
      user: {},
      newGgShow:false,
      NewGgTitle:'最新公告',
      NewGgContent:'',
      baseData:{
        mgCount:0,
        houseCount:0,
        carCount:0,
        carAreaCount:0,
        buildingCount:0,
        houseUserCount:0,
      },

      projects: [],
      loading: false,
      loadinggg: false,
      radarLoading: false,
      activities: [],
      teams: [],

      // data
      axis1Opts: {
        dataKey: 'item',
        line: null,
        tickLine: null,
        grid: {
          lineStyle: {
            lineDash: null
          },
          hideFirstLine: false
        }
      },
      axis2Opts: {
        dataKey: 'score',
        line: null,
        tickLine: null,
        grid: {
          type: 'polygon',
          lineStyle: {
            lineDash: null
          }
        }
      },
      scale: [{
        dataKey: 'score',
        min: 0,
        max: 80
      }],
      axisData: [
        { item: '引用', a: 70, b: 30, c: 40 },
        { item: '口碑', a: 60, b: 70, c: 40 },
        { item: '产量', a: 50, b: 60, c: 40 },
        { item: '贡献', a: 40, b: 50, c: 40 },
        { item: '热度', a: 60, b: 70, c: 40 },
        { item: '引用', a: 70, b: 50, c: 40 }
      ],
      radarData: [],
      newGg:[]
    }
  },
  computed: {
    ...mapState({
      nickname: (state) => state.user.nickname,
      welcome: (state) => state.user.welcome
    }),
    userInfo () {
      return this.$store.getters.userInfo
    }
  },
  created () {
    this.user = this.userInfo
    this.avatar = this.userInfo.avatar
  },
  mounted () {
    
    this.getBaes()
    this.getGg()
    this.initRadar()
  },
  methods: {
   ...mapGetters(['token', 'pmsArId', 'nowMg']),
    getBaes(){
      this.loading = true;
      this.axios({
        method:'post',
        url:'/community/getHomeBase',
        data:{token:this.token()}
      }).then(res => {
        this.loading = false;
        if(res.code === 0){
          this.baseData=res.data
          
        }else{
          this.$message.error(res.data.msg,2);
        }
      }).catch(err => {
        this.$message.error('服务器发生错误...',2);
        this.loading = false;
      })
    },
    getGg(){
      this.loadinggg = true;
      this.axios({
        method:'post',
        url:'/community/getNewGg',
        data:{token:this.token()}
      }).then(res => {
        this.loadinggg = false;
        if(res.code === 0){
          this.newGg=res.data
          
        }else{
          this.$message.error(res.data.msg,2);
        }
      }).catch(err => {
        this.$message.error('服务器发生错误...',2);
        this.loading = false;
      })
    },
    showOneNewGg(item){
      // if(this.newGg){
        this.newGgShow=true
        this.NewGgTitle=this.newGg[item].title
        this.NewGgContent=this.newGg[item].content
      // }
    },
    closeModels(){
      this.newGgShow=false
    },
    initRadar () {
      this.radarLoading = true

     
          let result=[
            {item:'孤寡老人',出小区:'20',入小区:'20'},
            {item:'50岁以上',出小区:'80',入小区:'10'},
            {item:'30岁以上',出小区:'40',入小区:'55'},
            {item:'重点关注',出小区:'44',入小区:'11'},
            {item:'待业青年',出小区:'44',入小区:'11'},
            {item:'外来务工',出小区:'44',入小区:'11'},
          ]
          const dv = new DataSet.View().source(result)
          
          dv.transform({
            type: 'fold',
            fields: ['出小区', '入小区'],
            key: 'user',
            value: 'score'
          })

          this.radarData = dv.rows
          this.radarLoading = false
      
    }
  }
}
</script>

<style lang="less" scoped>
  .project-list {

    .card-title {
      font-size: 0;
      margin-bottom:30px;
      a {
        color: rgba(0, 0, 0, 0.85);
        margin-left: 12px;
        line-height: 24px;
        height: 24px;
        display: inline-block;
        vertical-align: top;
        font-size: 14px;

        &:hover {
          color: #1890ff;
        }
      }
      .sttm{
        top:-10px;
        right: 0;
        font-size: 20px;
        position:absolute;
      }
    }
    .card-description {
      color: rgba(0, 0, 0, 0.45);
      height: 44px;
      line-height: 22px;
      overflow: hidden;
    }
    .project-item {
      display: flex;
      margin-top: 8px;
      overflow: hidden;
      font-size: 12px;
      height: 20px;
      line-height: 20px;
      justify-content: flex-end;
      a {
        color: rgba(0,0,0,.45);
        display: inline-block;
        margin-right: 8px;
        overflow: hidden;
        text-overflow: ellipsis;
        word-break: break-all;
        white-space: nowrap;
        flex:none;

        &:hover {
          color: #1890ff;
        }
      }
      .datetime {
        color: rgba(0, 0, 0, 0.25);
        flex: 0 0 auto;
        float: right;
      }
    }
    .ant-card-meta-description {
      color: rgba(0, 0, 0, 0.45);
      height: 44px;
      line-height: 22px;
      overflow: hidden;
    }
  }

  .item-group {
    padding: 20px 0 8px 24px;
    font-size: 0;
    a {
      color: rgba(0, 0, 0, 0.65);
      display: inline-block;
      font-size: 14px;
      margin-bottom: 13px;
      width: 25%;
    }
  }

  .members {
    a {
      display: block;
      margin: 12px 0;
      line-height: 24px;
      height: 24px;
      .member {
        font-size: 14px;
        color: rgba(0, 0, 0, .65);
        line-height: 24px;
        max-width: 100px;
        vertical-align: top;
        margin-left: 12px;
        transition: all 0.3s;
        display: inline-block;
      }
      &:hover {
        span {
          color: #1890ff;
        }
      }
    }
  }

  .mobile {

    .project-list {

      .project-card-grid {
        width: 100%;
      }
    }

    .more-info {
      border: 0;
      padding-top: 16px;
      margin: 16px 0 16px;
    }

    .headerContent .title .welcome-text {
      display: none;
    }
  }

</style>
